home *** CD-ROM | disk | FTP | other *** search
-
- /* Copyright 1986 Eric Jul. May not be used for any purpose without */
- /* written permission from the author. */
-
- /* Various timing routines */
- #include <stdio.h>
- #include <sys/time.h>
-
- #include "Kernel/h/assert.h"
- #include "Kernel/h/system.h"
- #include "Kernel/h/macros.h"f
- #include "Kernel/h/errMsgs.h"
- #include "Kernel/h/mmCodes.h"
- #include "Kernel/h/emTypes.h"
- #include "Kernel/h/timerTypes.h"
- #include "Kernel/h/kmdTypes.h"
- #include "Kernel/h/kEvents.h"
- #include "Kernel/h/emCodes.h"
- #include "Kernel/h/mmMsgTypes.h"
- #include "Kernel/h/lmTypes.h"
- #include "Kernel/h/emkDefs.h"
- #include "Kernel/h/lmCodes.h"
- #include "Kernel/h/hotsTypes.h"
- #include "Kernel/h/map.h"
- #include "Kernel/h/timeops.h"
- #include "Kernel/h/utils.h"
-
- /************************************************************************/
-
- int vTPingDataSize = 4; /* size in bytes of buffer to send */
- int vTPingCount = 1; /* loop count */
- int vTSleep = 4; /* Seconds to sleep before timing */
- int vTUseRawSend = 0; /* Use MM subnet type SNRAWMSG ? */
- int vTLMFillBuf = 0; /* Should the buffer be filled ? */
-
- int pingCount, thePingId, theLNN;
- int nextPingTimingId = 1;
- struct timeval theTime1, theTime2, diff;
-
- /************************************************************************/
- /* TDoPing */
- /************************************************************************/
-
- void TDoPing()
- /* Send out another ping msg or complete the timing.*/
- {
- register PingTimingReqItemPtr pingPtr;
- EmMsgPtr pingMsg;
- int size = sizeof(MessageHeader)+sizeof(PingTimingReqItem);
- KKStatus kstat;
-
- if (pingCount > 0) {
- kstat = MMAllocateMsg(size, (MessagePtr *)&pingMsg);
- assert(mSUCCESS(kstat));
- pingPtr = (PingTimingReqItemPtr) &pingMsg->itemHdr;
- pingPtr->hdr.itemTag = PingTimingITag;
- pingPtr->hdr.size = sizeof(PingTimingReqItem);
- pingPtr->reqId = thePingId;
- pingPtr->pingLNN = GetLNN();
- MMBuildMsg((MessagePtr)pingMsg, KMSG_EmKernel, EMKM_PingTimedReq,
- theLNN, (unsigned)size);
- kstat = vTUseRawSend ? MMSendRawMsg((MessagePtr) pingMsg) :
- MMSendMsg((MessagePtr) pingMsg);
- if ( !mSUCCESS(kstat) ) {
- ErrMsg("Could not send ping msg, status 0x%05x\n", kstat);
- pingCount = 0;
- return;
- }
- MMDeallocateMsg((MessagePtr) pingMsg);
- pingCount--;
- } else {
- xgettime(&theTime2);
- timeSub(diff, theTime2, theTime1);
- printf ("TPing %d loops in %2d.%06d seconds\n", vTPingCount,
- diff.tv_sec, diff.tv_usec);
- printf ("time per loop: %.3f microseconds\n",
- (diff.tv_sec * 1.0e6 + diff.tv_usec) / vTPingCount);
- }
- }
-
- HResult PingTimingReqHandler(fMsg)
- EmMsgPtr fMsg;
- /* Incoming msg handler for Ping Timing Req; returns a pong msg */
- {
- PingTimingReqItemPtr pingPtr;
- PongTimingReqItemPtr pongPtr;
- EmMsgPtr replyPtr;
- int size = sizeof(MessageHeader) + sizeof(PingTimingReqItem);
- KKStatus kstat;
-
- pingPtr = (PingTimingReqItemPtr) &(fMsg->itemHdr);
-
- if (pingPtr->hdr.itemTag != PingTimingITag) {
- ErrMsg("PingTimingReq: Bad item tag = %s\n",
- PPITag(pingPtr->hdr.itemTag));
- MMDeallocateMsg((MessagePtr) fMsg);
- return;
- }
- DebugMsg(2, "PingTimingReq from LNN %d, reqId %d replying ...\n",
- pingPtr->pingLNN, pingPtr->reqId);
- kstat = MMAllocateMsg(size, (MessagePtr *)&replyPtr);
- assert(mSUCCESS(kstat));
- pongPtr = (PongTimingReqItemPtr) &(replyPtr->itemHdr);
- pongPtr->hdr.itemTag = PongTimingITag;
- pongPtr->hdr.size = sizeof(PongTimingReqItem);
- pongPtr->reqId = pingPtr->reqId;
- pongPtr->pongLNN = GetLNN();
- MMBuildMsg((MessagePtr)replyPtr, KMSG_EmKernel, EMKM_PongTimedReq,
- pingPtr->pingLNN, (unsigned)size);
- kstat = vTUseRawSend ? MMSendRawMsg((MessagePtr) replyPtr) :
- MMSendMsg((MessagePtr) replyPtr);
- if ( !mSUCCESS(kstat) ) {
- DebugMsg(1, "Could not send pong msg, status 0x%05x\n", kstat);
- PutEdenMsg((int)kstat, (FILE *)NULL, (char **)0);
- }
- MMDeallocateMsg((MessagePtr) fMsg);
- MMDeallocateMsg((MessagePtr) replyPtr);
- }
-
- HResult PongTimingReqHandler(fMsg)
- EmMsgPtr fMsg;
- {
- PongTimingReqItemPtr pongPtr = (PongTimingReqItemPtr) &fMsg->itemHdr;
-
- if (pongPtr->hdr.itemTag != PongTimingITag) {
- DebugMsg(1, "PongTimingReq: Bad item tag = %d\n", pongPtr->hdr.itemTag);
- MMDeallocateMsg((MessagePtr) fMsg);
- return;
- }
- DebugMsg(1, "PongTimingReply recieved from LNN %d, reqId %d\n",
- pongPtr->pongLNN, pongPtr->reqId);
- MMDeallocateMsg((MessagePtr) fMsg);
-
- /* Let TDoPing complete the timing */
- TDoPing();
- }
-
- HResult TStartPing()
- /* Scheduled to run by TPingTiming */
- {
- xgettime(&theTime1);
- TDoPing();
- }
-
- /* Snapshot */
- void TPingTiming(fLNN)
- int fLNN;
- {
- HOTSRecord *HOTSPtr;
-
- KMDPrint("TPingTiming, sending %d ping%s to LNN %d, %s\n", vTPingCount,
- mPLURAL(vTPingCount), fLNN, vTUseRawSend?"RAW":"flow-controlled");
- if (!mSUCCESS(HOTSSearchPtr(fLNN, &HOTSPtr)) ||
- ((HOTSPtr->NodeStat != Alive) && (HOTSPtr->NodeStat != Booting)) ) {
- KMDPrint("Node %d not alive\n", fLNN);
- return;
- }
- theLNN = fLNN;
- thePingId = nextPingTimingId++;
- pingCount = vTPingCount;
- MMSetTimer((unsigned)vTSleep, (HandlerPtr)TStartPing, 0, (TimerId *)0);
- }
-
- /************************************************************************/
- /* TLMPingTiming-pong message protocol: */
- /* PingTiming messages can be sent kernel-kernel at anytime. */
- /* The receiving kernel merely responds with a pong message. */
- /* Usefullness: For timing LM messages */
- /************************************************************************/
-
- /* Read a LM msg and send back a LM msg of the same size */
- HResult TLMPingTimingReqHandler(fHandle)
- LMHandle fHandle;
- {
- LMHandle myHandle = fHandle;
- int length, i, sum, lnn;
- int buf[2000];
-
- lnn = fHandle->mmMsgHdr.MsgSrc;
- sum = 0;
-
- do {
- length = 2000 * sizeof(int);
- LMGetData(&myHandle, &buf[0], &length);
- if (length >0) {
- sum += length;
- }
- } while (length > 0);
- LMClose(&myHandle);
- LMStartMsg(&myHandle, KMSG_EmKernel, EMKM_LMPongTimedReq, lnn);
- if (vTLMFillBuf) {
- for (i = 0; i < sum; i += sizeof(int)) {
- LMPutData(&myHandle, &i, sizeof(int));
- }
- } else {
- LMPutData(&myHandle, (int *) 0, sum);
- }
- LMSendMsg(&myHandle);
- }
-
- /* Forward */ void TLMDoPing();
-
- /* Read a LM msg and continue timing */
- HResult TLMPongTimingReqHandler(fHandle)
- LMHandle fHandle;
- {
- LMHandle myHandle = fHandle;
- int length;
- int buf[2000];
-
- do {
- length = 2000* sizeof(int);
- LMGetData(&myHandle, &buf[0], &length);
- } while (length > 0);
- LMClose(&myHandle);
- pingCount--;
- TLMDoPing();
- }
-
- void TLMDoPing()
- {
- LMHandle myHandle;
- int i;
-
- if(pingCount > 0) {
- LMStartMsg(&myHandle, KMSG_EmKernel, EMKM_LMPingTimedReq, theLNN);
- if (vTLMFillBuf)
- for (i = 0; i < vTPingDataSize; i += sizeof(int)) {
- LMPutData(&myHandle, &i, sizeof(int));
- } else LMPutData(&myHandle, (int *) 0, vTPingDataSize);
- LMSendMsg(&myHandle);
- } else {
- xgettime(&theTime2);
- timeSub(diff, theTime2, theTime1);
- printf ("TLMPing %d bytes, %d loops in %2d.%06d seconds\n",
- vTPingDataSize, vTPingCount, diff.tv_sec, diff.tv_usec);
- printf ("time per loop: %.3f microseconds\n",
- (diff.tv_sec * 1.0e6 + diff.tv_usec) / vTPingCount);
- }
- }
-
- HResult TLMStartPing()
- /* Scheduled to run by TLMPingTiming */
- {
- xgettime(&theTime1);
- TLMDoPing();
- }
-
- /* Snapshot */
- void TLMPingTiming(fLNN)
- int fLNN;
- {
- HOTSRecord *HOTSPtr;
-
- KMDPrint("TLMPingTiming to LNN %d, size = %d, count = %d\n", fLNN,
- vTPingDataSize, vTPingCount);
- KMDPrint("Start timing in %d seconds; output to kernel stdout\n",
- vTSleep);
- KMDPrint("Use ChangeVar snapshot to modify parameters %s\n",
- "vTPingDataSize and vTPingCount");
-
- if (!mSUCCESS(HOTSSearchPtr(fLNN, &HOTSPtr)) ||
- ((HOTSPtr->NodeStat != Alive) && (HOTSPtr->NodeStat != Booting)) ) {
- KMDPrint("Node %d not alive\n", fLNN);
- return;
- }
- theLNN = fLNN;
- thePingId = nextPingTimingId++;
- pingCount = vTPingCount;
- MMSetTimer((unsigned)vTSleep, (HandlerPtr)TLMStartPing, 0, (TimerId *)0);
- }
-
- /************************************************************************/
- void TimingInit()
- /* Called at kernel boot time */
- {
- KMDSetSnap(TPingTiming);
- KMDSetSnap(TLMPingTiming);
- KMDSetVar(vTPingDataSize);
- MMDefineMsgHandler(KMSG_EmKernel,EMKM_PingTimedReq,
- (HandlerPtr)PingTimingReqHandler, (HandlerPtr *)NULL);
- MMDefineMsgHandler(KMSG_EmKernel, EMKM_PongTimedReq,
- (HandlerPtr)PongTimingReqHandler, (HandlerPtr *)NULL);
- MMDefineMsgHandler(KMSG_EmKernel, EMKM_LMPingTimedReq,
- (HandlerPtr)TLMPingTimingReqHandler, (HandlerPtr *)NULL);
- MMDefineMsgHandler(KMSG_EmKernel, EMKM_LMPongTimedReq,
- (HandlerPtr)TLMPongTimingReqHandler, (HandlerPtr *)NULL);
- }
-
-